from common.base import Base, By


class SellerCenterPage(Base):

    # 封装表现层
    username_loc = (By.NAME,'username') # 用户名输入框
    password_loc = (By.NAME,'password') # 密码输入框
    login_loc = (By.ID, 'login') # 登录按钮
    product_module_loc = (By.LINK_TEXT, '商品模块') # 左侧菜单：商品模块
    add_product_loc = (By.LINK_TEXT, '添加普通商品') # 左侧菜单：添加普通商品
    product_name_loc = (By.NAME,'name') # 商品名称输入框
    search_words_loc = (By.NAME,'search_words') # 关键词输入框
    goodsCategoryButton_loc = (By.NAME,'_goodsCategoryButton') # 设置分类按钮
    # Iframe标签，本页面不用，测试用例用
    iframe_loc = (By.CSS_SELECTOR,'body > div.aui_state_focus > div > table > tbody > tr:nth-child(2) > td.aui_c > div > table > tbody > tr:nth-child(2) > td.aui_main > div > iframe')
    food_and_beverage_loc = (By.XPATH,'//span[text()="食品饮料"]') # 食品饮料分类
    imported_food_loc = (By.XPATH, '//span[text()="进口食品"]')  # 进口食品 二级分类
    confirm_button_loc = (By.XPATH, '//button[text()="确定"]')  # 商品分类 确定按钮
    sort_loc = (By.NAME,'sort') # 商品排序输入框
    unit_loc = (By.NAME, 'unit')  # 计件单位显示框
    free_shipping_loc = (By.CSS_SELECTOR, '#tab1 > div:nth-child(7) > div > div:nth-child(1) > label') # 是否免运费单选框，选择是
    market_price_loc = (By.NAME, '_market_price[0]')  # 市场价格输入框
    sell_price_loc = (By.NAME, '_sell_price[0]')  # 销售价格输入框
    cost_price_loc = (By.NAME, '_cost_price[0]')  # 成本价格输入框
    brand_id_loc = (By.NAME, 'brand_id')  # 商品品牌，下拉选择框，本页面不用，测试用例用
    fileUpload_loc = (By.ID, 'fileUpload') # 产品相册 选择文件按钮
    publish_product_confirm_button_loc = (By.CSS_SELECTOR, 'div>input[value="确 定"]') # 商品发布 确定按钮



    # 封装操作层
    # 卖家登录流程
    def process_seller_login(self,acc,pwd):
        self.send_keys(SellerCenterPage.username_loc,acc)
        self.send_keys(SellerCenterPage.password_loc,pwd)
        self.click(SellerCenterPage.login_loc)

    # 点击商品模块
    def click_product_module(self):
        self.click(SellerCenterPage.product_module_loc)

    # 点击添加普通商品
    def click_add_product(self):
        self.click(SellerCenterPage.add_product_loc)

    # 输入商品标题
    def input_product_name(self,text):
        self.send_keys(SellerCenterPage.product_name_loc,text)

    # 输入关键词
    def input_search_words(self,text):
        self.send_keys(SellerCenterPage.search_words_loc,text)

    # 点击设置分类按钮
    def click_goodsCategoryButton(self):
        self.click(SellerCenterPage.goodsCategoryButton_loc)

    # 点击食品饮料 分类
    def click_food_and_beverage(self):
        self.click(SellerCenterPage.food_and_beverage_loc)

    # 点击进口食品 分类
    def click_imported_food(self):
        self.click(SellerCenterPage.imported_food_loc)

    # 点击分类确定按钮
    def click_confirm_button(self):
        self.click(SellerCenterPage.confirm_button_loc)

    # 输入商品排序
    def input_sort(self,text):
        self.send_keys(SellerCenterPage.sort_loc,text)

    # 输入计件单位
    def input_unit(self,text):
        self.send_keys(SellerCenterPage.unit_loc,text)

    # 点击是否免运费单选框，选择是
    def click_free_shipping(self):
        self.click(SellerCenterPage.free_shipping_loc)

    # 输入市场价格
    def input_market_price(self,text):
        self.send_keys(SellerCenterPage.market_price_loc,text)

    # 输入销售价格
    def input_sell_price(self,text):
        self.send_keys(SellerCenterPage.sell_price_loc,text)

    # 输入成本价格
    def input_cost_price(self,text):
        self.send_keys(SellerCenterPage.cost_price_loc,text)

    # 上传产品相册
    def input_fileUpload(self,text):
        self.send_keys(SellerCenterPage.fileUpload_loc,text)

    # 点击确认发布商品按钮
    def publish_product_confirm_button(self):
        self.click(SellerCenterPage.publish_product_confirm_button_loc)

